package gestordeentidades.persistance.database;

import java.sql.Date;
import java.util.HashMap;
import java.util.NoSuchElementException;
import gestordeentidades.persistance.interfaces.ILinha;

/**
 * Trabalho DAS - 2014/2015
 * Class que implementa ILinha, é um HashMap String, Object
 * @author a21210380, a21190325, a21210392
 */
public class Linha extends HashMap<String, Object> implements ILinha {

    public Linha(int columnCount) {
        super(columnCount);
    }
    
    @Override
    public Integer getInteger(String key) {
        if(containsKey(key)) {
            return (Integer)get(key);
        }
        throw new NoSuchElementException(key);
    }
    
    @Override
    public int getInt(String key) {
        if(containsKey(key))
            return (int) get(key);
        throw new NoSuchElementException(key);
    }
    
    @Override
    public long getLong(String key) {
        if(containsKey(key))
            return ((Integer)get(key)).longValue();
        throw new NoSuchElementException(key);
    }
    
    @Override
    public float getFloat(String key) {
        if(containsKey(key))
            return ((Double)get(key)).floatValue();
        throw new NoSuchElementException(key);
    }
    
    @Override
    public double getDouble(String key) {
        if(containsKey(key))
            return (double) get(key);
        throw new NoSuchElementException(key);
    }
    
    @Override
    public boolean getBoolean(String key) {
        if(containsKey(key))
            return get(key).equals(1);
        throw new NoSuchElementException(key);
    }
    
    @Override
    public String getString(String key) {
        if(containsKey(key))
            return (String) get(key);
        throw new NoSuchElementException(key);
    }
    
    @Override
    public Date getDate(String key) {
        if(containsKey(key))
            return new Date((long)get(key));
        throw new NoSuchElementException(key);
    }
}
